﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CheckLift.Common.Intf;
using System.Data.Linq;
using CheckLift.Common.Impl;

namespace CheckLift.Linq
{
    public partial class Report : IReport
    {
        private Dictionary<string, ReportPropertiesVal> reportValDict = new Dictionary<string, ReportPropertiesVal>();

        #region IReport Members

        partial void OnCreated()
        {
            ReportValues.ListChanged += new System.ComponentModel.ListChangedEventHandler(ReportValues_ListChanged);
        }

        void ReportValues_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
        {
            reportValDict.Clear();
            foreach (ReportValue item in ReportValues)
            {
                ReportPropertiesVal val = new ReportPropertiesVal((IProperty)item.Property){ Value = item.PropertyValue};                 
                reportValDict.Add(item.Property.Name, val );

            }
            
        }

        ILift IReport.Lift
        {
            get { return (ILift)Lift; }
        }

        IReportData IReport.ReportData
        {
            get { return (IReportData)ReportData; }
        }

        EntitySet<IReportValue> IReport.ReportValues
        {
            get 
            {
                EntitySet<IReportValue> entitySetRes = new EntitySet<IReportValue>();
                foreach (ReportValue item in ReportValues)
                {
                    entitySetRes.Add((IReportValue)item);
                }
                
                return entitySetRes;                
            }
        }

        Dictionary<string, ReportPropertiesVal> IReport.ReportValuesDict
        {
            get
            {
                return reportValDict;
            }            
        }

        #endregion
  
    }
}
